<template>
  <div>
    <!-- 顶部滑动条区域 -->
    <div id="slider" class="mui-slider">
      <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in cates" :key='item.id' @click="getImgs(item.id)">
            {{ item.title }}
          </a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul class="photo-list">
      <router-link :to="'/home/photoInfo/' + item.id"  v-for="item in imgs" :key='item.id' tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <h1 class="info-title">{{ item.title }}</h1>
          <div class="info-body">{{ item.img_title }}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import { Toast } from 'mint-ui'
// import mui from '../../assets/lib/js/mui.min.js'

export default{
  data () {
    return {
      cates: [], // 标题滑动列表
      imgs: [] // 图片列表
    }
  },
  created () {
    this.getCates()
    this.getImgs(0)
  },
  mounted () {
    // mui('.mui-scroll-wrapper').scroll({
    //   deceleration: 0.0005 // flick 减速系数，系数越大，滚动速度越慢，滚动距离越小 默认值:0.0006
    // });
  },
  methods: {
    getCates () {
      this.$http.get('http://localhost:8080/api/getCates').then(result => {
        if (result.status === 200) {
          result.data.unshift({id: 0, title: '全部'})
          this.cates = result.data
        } else {
          Toast('获取导航栏失败')
        }
      })
    },
    getImgs (id) {
      this.$http.get('http://localhost:8080/api/getImgs/' + id).then(result => {
        if (result.status === 200) {
          this.imgs = result.data
        } else {
          Toast('获取图片信息失败')
        }
      })
    }
  }
}
</script>

<style scoped>
* {
  touch-action: pan-y;
}
.photo-list{
  list-style: none;
  margin: 0;
  padding: 10px;
  margin-bottom: 0;
  vertical-align: middle;
}
.photo-list img[lazy=loading]{
  width: 40px;
  height: 300px;
  margin: auto;
}
.photo-list li{
  box-shadow: 0 0 6px #000;
  /* background-color: #ccc; */
  text-align: center;
  position: relative;
}
.photo-list img{
  width:100%;
}
.info{
  color:#fff;
  text-align: left;
  position: absolute;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  max-height: 84px;
}
.info .info-title{
  font-size: 14px;
}
.info .info-body{
  font-size: 13px;
}
</style>
